package netTracker.network;

public class PingServer
{	public static final int PING_P = 7879;

	public static void main (String[] args) throws Exception{	
		Address localAddress = new Address ("127.0.0.1", PING_P);
		PostOffice pobox = new PostOffice (localAddress);
		AddressFactory myAddrFactory = new AddressFactory(pobox);
	
		localAddress = myAddrFactory.makeAddress(localAddress);
		System.out.println("Joined name server. new address: "+localAddress);
		
		Address echoAddress = new Address("127.0.0.1", EchoServer.ECHO_P);
		int echoID = pobox.lookup(echoAddress);
		System.out.println("Looked up address of echoServer. ID: "+echoID);
		echoAddress.setID(echoID);
		
		Message m = new Message (localAddress.getID()+" says hello to "+echoAddress.getID());

		pobox.send (m, echoAddress);
		m = pobox.receive ();
		System.out.println (m.getMsg ());
		System.exit(0);
	} // main
} 
